package top.kaoshanji.s1ch09a;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.BDDMockito;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.ui.Model;

/**
 * @author kaoshanji
 * ^_^
 * create time 2025/4/30 15:56
 */
@ExtendWith(MockitoExtension.class)
public class LoginControllerUnitTests {

    @Mock
    private Model model;

    @Mock
    private LoginProcessor loginProcessor;

    @InjectMocks
    private LoginController loginController;

    /**
     * 代码清单test-s1ch09a-01：测试一下登录通过的场景
     */
    @Test
    public void loginPostLoginSucceedsTest() {
        BDDMockito.given(loginProcessor.login()).willReturn(true);

        String result = loginController.loginPost("username", "password", model);

        Assertions.assertEquals("login.html", result);

        Mockito.verify(model).addAttribute("message", "You are now logged in.");
    }

}
